<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of MiCrud
 *
 * @author Nahuel Chaves
 */
class MiCrud extends CrudCode {

    public function generateActiveField($modelClass, $column, $claseCSS = null) {

        if ($column->type === 'boolean')
            return "\$form->checkBox(\$model,'{$column->name}')";
        else if (stripos($column->dbType, 'text') !== false) {
            if ($claseCSS == null)
                return "\$form->textArea(\$model,'{$column->name}',array('rows'=>6, 'cols'=>50))";
            else
                return "\$form->textArea(\$model,'{$column->name}',array('rows'=>6, 'cols'=>50,'class' =>'$claseCSS'))";
        } else {
            if (preg_match('/^(password|pass|passwd|passcode)$/i', $column->name))
                $inputField = 'passwordField';
            else
                $inputField='textField';

            if ($column->type !== 'string' || $column->size === null)
            {
                if ($claseCSS == null)
                    return "\$form->{$inputField}(\$model,'{$column->name}')";
                else {
                    
                    return "\$form->{$inputField}(\$model,'{$column->name}',array('class'=>'$claseCSS'))";
                }
            }
            else {
                if (($size = $maxLength = $column->size) > 60)
                    $size = 60; {
                        if ($claseCSS == null)
                            return "\$form->{$inputField}(\$model,'{$column->name}',array('size'=>$size,'maxlength'=>$maxLength))";
                        else
                            return "\$form->{$inputField}(\$model,'{$column->name}',array('size'=>$size,'maxlength'=>$maxLength,'class'=>'$claseCSS'))";
                }
            }
        }
    }

}

?>
